package com.study.sbsummary.context;

public class RequestContext {
    private static final ThreadLocal<RequestContext> CONTEXT = new ThreadLocal<>();

    private boolean onlineTest;

    public static RequestContext get() {
        RequestContext requestContext = CONTEXT.get();
        if (requestContext == null) {
            requestContext = new RequestContext();
            CONTEXT.set(requestContext);
        }
        return requestContext;
    }

    public static boolean isOnlineTest() {
        RequestContext requestContext = CONTEXT.get();
        if (requestContext != null) {
            return requestContext.onlineTest;
        }
        return false;
    }

    public static void onlineTest(boolean onlineTest) {
        get().onlineTest = onlineTest;
    }

    public static void reset() {
        RequestContext requestContext = CONTEXT.get();
        if (requestContext != null) {
            requestContext.onlineTest = false;
        }
    }

    public static void clear() {
        CONTEXT.remove();
    }
}
